package com.huizu.project.apiController;

import com.huizu.common.annotation.Anonymous;
import com.huizu.common.annotation.Log;
import com.huizu.common.core.controller.BaseController;
import com.huizu.common.core.domain.AjaxResult;
import com.huizu.common.core.page.TableDataInfo;
import com.huizu.common.enums.BusinessType;
import com.huizu.common.utils.poi.ExcelUtil;
import com.huizu.project.config.TerAspect;
import com.huizu.project.config.UserAspect;
import com.huizu.project.domain.*;
import com.huizu.project.service.IProLdConfigService;
import com.huizu.project.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 基础劳动配置Controller
 * 
 * @author zhangmx
 * @date 2024-05-11
 */
@Anonymous
@RestController
@RequestMapping("/api/proldconfig")
public class ApiProLdConfigController extends BaseController
{
    @Autowired
    private IProLdConfigService proLdConfigService;

    /**
     * 查询基础劳动配置列表
     */
    @PostMapping("/list")
    public TableDataInfo list(ProLdConfig proLdConfig, HttpServletRequest request)
    {
//        startPage();
        String token = request.getHeader(TokenUtils.getAppTokenHeader());
        String userId = TokenUtils.parseToken(token);//获取用户id
        proLdConfig.setBeUserId(userId);
        return getDataTable(proLdConfigService.selectProLdConfigListApi(proLdConfig));
    }

    /**
     * 查询用户积分列表
     */
    @UserAspect
    @PostMapping("/listByUser")
    public AjaxResult listByUser(ProLdConfig proLdConfig, HttpServletRequest request)
    {

        String token = request.getHeader(TokenUtils.getAppTokenHeader());
        String userId = TokenUtils.parseToken(token);//获取用户id
        proLdConfig.setBeUserId(userId);
        return success(proLdConfigService.selectProLdConfigByUserApi(proLdConfig));
    }


    /**
     * 获取基础劳动配置详细信息
     */
    @PostMapping(value = "/getById")
    public AjaxResult getInfo(@RequestBody ProLdConfig proLdConfig)
    {
        String id = proLdConfig.getId();
        return success(proLdConfigService.selectProLdConfigById(id));
    }

    @PostMapping("/listJb")
    public TableDataInfo listJb(){
        List<ProLdJb> list =  proLdConfigService.listJb();
        return getDataTable(list);
    }

    @PostMapping("/listDj")
    public TableDataInfo listDj(){
        List<ProLdDj> list = proLdConfigService.listDj();
        return getDataTable(list);
    }

    @PostMapping("/listWc")
    public TableDataInfo listWc(){
        List<ProLdWc> list = proLdConfigService.listWc();
        return getDataTable(list);
    }

    @PostMapping("/listFs")
    public TableDataInfo proLdFsList(){
        List<ProLdFs> list = proLdConfigService.proLdFsList();
        return getDataTable(list);
    }

    /**
     * 查询用户积分列表
     */
    @TerAspect
    @PostMapping("/listByBeUser")
    public AjaxResult listByBeUser(@RequestBody ProLdConfig proLdConfig, HttpServletRequest request)
    {
        return success(proLdConfigService.selectProLdConfigByUserApi(proLdConfig));
    }

    /**
     * 获取我的劳动封装列表
     * @return
     */
    @PostMapping("/listLdUtilsByUser")
    public TableDataInfo listLdUtils(@RequestBody Map<String,Object> map,HttpServletRequest request){
        startPage();
        String token = request.getHeader(TokenUtils.getAppTokenHeader());
        String userId = TokenUtils.parseToken(token);//获取用户id
        map.put("userId",userId);
        return getDataTable(proLdConfigService.listLdUtils(map));
    }

    /**
     * 首页我的劳动条数分析
     * @return
     */
    @PostMapping("/myLdAnalysis")
    public AjaxResult myLdAnalysis(HttpServletRequest request){
        String token = request.getHeader(TokenUtils.getAppTokenHeader());
        String userId = TokenUtils.parseToken(token);//获取用户id
        return success(proLdConfigService.myLdAnalysis(userId));
    }

    /**
     * 获取我的劳动封装列表
     * @return
     */
    @PostMapping("/listLdUtilsByUserReject")
    public TableDataInfo listLdUtilsByUserReject(@RequestBody Map<String,Object> map,HttpServletRequest request){
        String token = request.getHeader(TokenUtils.getAppTokenHeader());
        String userId = TokenUtils.parseToken(token);//获取用户id
        map.put("userId",userId);
        map.put("status","3");
        return getDataTable(proLdConfigService.listLdUtils(map));
    }

    /**
     * 获取劳动封装列表
     * @return
     */
    @PostMapping("/listLdUtilsByTer")
    public TableDataInfo listLdUtilsByUserTer(@RequestBody Map<String,Object> map,HttpServletRequest request){
        String token = request.getHeader(TokenUtils.getAppTokenHeader());
        String userId = TokenUtils.parseToken(token);//获取用户id
        map.put("terId",userId);
        return getDataTable(proLdConfigService.listLdUtils(map));
    }


}
